package com.quicklife.util;

import java.sql.Date;
import java.sql.Timestamp;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.UUID;

public class StringUtil {
	/**
	 * SUCCESS
	 */
	public static String RESULT_CODE_OK = "SUCCESS";
	/**
	 * FAIL
	 */
	public static String RESULT_CODE_FAIL = "FAIL";
	/**
	 * 服务器异常
	 */
	public static String RESULT_EXCEPTION = "服务器异常";
	/**
	 * 登陆名已被注
	 */
	public static String FAIL_LNAME_EXIST = "登陆名已被注册";
	/**
	 * 昵称已被注
	 */
	public static String FAIL_NICKNAME_EXIST = "昵称已被注册";
	/**
	 * 手机号已被注册
	 */
	public static String FAIL_PHONE_EXIST = "手机号已被注册";
	/**
	 * 邮箱已被注册
	 */
	public static String FAIL_EMAIL_EXIST = "邮箱已被注册";

	/**
	 * 旧密码不正确
	 */
	public static String FAIL_ODPSW_ERR = "旧密码不正确";

	/**
	 * 更新成功
	 */
	public static String RESULT_SUCESS_UPDATE = "更新成功";

	public static String toString(Object object) {
		return String.valueOf(object);
	}

	/**
	 * 将Integer格式String转为Integer
	 * 
	 * @param s
	 * @return
	 */
	public static Integer toInt(String s) {
		return Integer.parseInt(s);
	}

	/**
	 * 将Double格式String转为Double
	 * 
	 * @param s
	 * @return
	 */
	public static Double toDouble(String s) {
		return Double.parseDouble(s);
	}

	/**
	 * 获取UUID
	 * 
	 * @return UUID
	 */
	public static String getUUID() {
		UUID uuid = UUID.randomUUID();

		return uuid.toString();
	}

	/**
	 * 判断是否为空字符串
	 * 
	 * @return
	 */
	public static boolean isNull(String str) {
		if (str == null || "".equals(str)) {
			return true;
		}

		return false;
	}

	/**
	 * 字符串转sql Timestamp
	 * 
	 * @param dateStr
	 * @return
	 */
	public static Timestamp stringToSqlTimestamp(String dateStr) {
		Timestamp result = null;
		try {
			Timestamp timestamp = Timestamp.valueOf(dateStr);
			result = timestamp;
		} catch (Exception e) {
			e.printStackTrace();
		}

		return result;
	}

	/**
	 * 字符串转sql date
	 * 
	 * @param dateStr
	 * @return
	 */
	public static Date stringToSqlDate(String dateStr) {
		Date result = null;
		try {
			result = Date.valueOf(dateStr);
		} catch (Exception e) {
			e.printStackTrace();
		}

		return result;
	}
	
	public static void main(String[] args) {
		System.out.println(getUUID());
	}
}
